Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for transition:persist directive #840

Merged
merged 8 commits into from
Aug 2, 2023
Merged

Support for transition:persist directive #840

merged 8 commits into from
Aug 2, 2023

Conversation

matthewp
Copy link
Contributor

@matthewp matthewp commented Jul 28, 2023

Changes

  • Adds support for transition:persist. In terms of the compiler this works a lot like transition:name and transition:animate, but calls a different function createTransitionScope which creates a distinct name so that the element can be found on the new page.
  • Tried to add helpful comments.
  • Introduces experimentalPersistence because there is a new exported function, so this flag is needed to prevent breakage when using a new compiler version with an old Astro version (unlikely).

Testing

  • Tests are in the printer.

Docs

  • N/A

@changeset-bot
Copy link

changeset-bot bot commented Jul 28, 2023

🦋 Changeset detected

Latest commit: e625f45

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/compiler Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@matthewp
Copy link
Contributor Author

!preview view-transitions

@github-actions
Copy link
Contributor

 > [email protected] release /home/runner/work/compiler/compiler > changeset publish "--tag" "next--view-transitions" 🦋 warn ===============================IMPORTANT!=============================== 🦋 warn Packages will be released under the next--view-transitions tag 🦋 warn ---------------------------------------------------------------------- 🦋 info npm info @astrojs/compiler 🦋 warn @astrojs/compiler is not being published because version 1.6.3 is already published on npm 🦋 warn No unpublished projects to publish

@matthewp
Copy link
Contributor Author

!preview view-transitions

@github-actions
Copy link
Contributor

 > [email protected] release /home/runner/work/compiler/compiler > changeset publish "--tag" "next--view-transitions" 🦋 warn ===============================IMPORTANT!=============================== 🦋 warn Packages will be released under the next--view-transitions tag 🦋 warn ---------------------------------------------------------------------- 🦋 info npm info @astrojs/compiler 🦋 info @astrojs/compiler is being published because our local version (0.0.0-view-transitions-20230728203621) has not been published on npm 🦋 info Publishing "@astrojs/compiler" at "0.0.0-view-transitions-20230728203621" 🦋 success packages published successfully: 🦋 @astrojs/[email protected] 🦋 Creating git tag... 🦋 New tag: @astrojs/[email protected]

p.println(fmt.Sprintf("}, %s, %s);", filenameArg, propagationArg))
p.println(fmt.Sprintf("export default %s;", componentName))
}

var skippedAttributes = map[string]bool{
"define:vars": true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are exactly the same except that the object form doesn't skip define:vars.

// If there no value, create a transition scope for this element
if n.Attr[transitionPersistIndex].Val != "" {
// Just rename the attribute
n.Attr[transitionPersistIndex].Key = "data-astro-transition-persist"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<div transition:persist="media-player"> we only need to transform this to a data-attribute. No runtime processing is needed.

// Just rename the attribute
n.Attr[transitionPersistIndex].Key = "data-astro-transition-persist"

} else if transform.HasAttr(n, transform.TRANSITION_NAME) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is a transition:name on the element, use that as the persist value as well.

<div transition:name="media-player" transition:persist> This just avoids repeating the same thing.

n.Attr[transitionPersistIndex].Type = transitionNameAttr.Type
} else {
fmt.Printf("NO VALUE - %v\n", n.TransitionScope)
n.Attr = append(n.Attr, astro.Attribute{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No value provided, so we will assign a value at runtime based on the position of the element within the component and the number of times this component has been used. This is the same algorithm used to auto-name view-transition-name. Subject to change/better algorithm.

<div transition:persist>

@matthewp matthewp changed the title Persist Support for transition:persist directive Jul 31, 2023
@matthewp matthewp marked this pull request as ready for review July 31, 2023 14:39
@matthewp
Copy link
Contributor Author

!preview view-transitions

@github-actions
Copy link
Contributor

 > [email protected] release /home/runner/work/compiler/compiler > changeset publish "--tag" "next--view-transitions" 🦋 warn ===============================IMPORTANT!=============================== 🦋 warn Packages will be released under the next--view-transitions tag 🦋 warn ---------------------------------------------------------------------- 🦋 info npm info @astrojs/compiler 🦋 info @astrojs/compiler is being published because our local version (0.0.0-view-transitions-20230731144215) has not been published on npm 🦋 info Publishing "@astrojs/compiler" at "0.0.0-view-transitions-20230731144215" 🦋 success packages published successfully: 🦋 @astrojs/[email protected] 🦋 Creating git tag... 🦋 New tag: @astrojs/[email protected]

@matthewp matthewp merged commit 365710c into main Aug 2, 2023
5 checks passed
@matthewp matthewp deleted the persist branch August 2, 2023 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant